import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-11-06
 * Time: 18:20
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        while (scan.hasNextInt()) {
            int n = scan.nextInt();
            int ret = func(n);
            System.out.println(ret);
        }

    }

    private static int func(int n) {
            int f1 = 0;
            int f2 = 1;
            int f3 = 0;
            while (f3 < n){
                f3 = f1 + f2;
                if (f3 >= n){
                    break;
                }
                f1 = f2;
                f2 = f3;
            }
            return Math.abs(f2-n) < Math.abs(f3 - n)?Math.abs(f2-n):Math.abs(f3 - n) ;

    }
}
